
<?php

defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;

$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
$uniacid = $_SESSION['uniacid'];
$mid = $_SESSION['uid'];
$basic=$this->plugin_setting('basic');
$basic['bankuai1']=$basic['bankuai'];
$return['setting']=$return['basic']=$basic;
if($_RQ['op']=='main'){
	/*******main*******/
	$return['category']=pdo_getall('jy_aligroup_groups_category',array('uniacid'=>$_SESSION['uniacid'],'status'=>1));
	$return['sharedata']=array(
			'title'=>$basic['share_title']?$basic['share_title']:'首页-在线拼团',
			'desc'=>$basic['share_desc']?$basic['share_desc']:'在线拼团商城！',
			'link'=>custom_url('jy_aligroup/index//fromuser='.$_SESSION['uid'],true),
			'imgUrl'=>tomedia($basic['share_image'])
	);
	$return['params']=array('cid'=>0,'isindex'=>1,'status'=>1);
	set_html('title',$basic['title']?:'拼团首页');
	exi($return);
}
if($_RQ['op']=='getlist'){
	//首页推荐活动
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=$params=array();
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$status=intval($_RQ['status']);
	$num=intval($_RQ['num']);
	if($_RQ['keyword']){
		$params['title like']='%'.$_RQ['keyword'].'%';
		$return['params']['keyword']=$_RQ['keyword'];
	}
	if($_RQ['isindex']){
		$params['isindex']=1;
		$return['params']['isindex']=1;
	}
	if($_RQ['cid']){
		$params['categoryid']=intval($_RQ['cid']);
		$return['params']['cid']=intval($_RQ['cid']);
	}
	if($status==2){
		$params['starttime >']=time();
		$return['params']['status']=2;
	}else{
		$params['starttime <']=time();
		$params['endtime >']=time();
		$return['params']['status']=1;
	}
	if($num){
		$psize = $num;
	}
	$fields=array('id','uniacid','title','desc','image','status','goodsid','feetype','price','agio','goodsnum','sales','teamnum','groupnum','endtime','isindex','ishot','displayorder','single','createtime');
	$groups=pdo_getslice('jy_aligroup_groups',$params,array($pindex,$psize),$total,$fields,'','displayorder desc');
	$groups_count=count($groups);
	if($groups){
		foreach($groups as &$item){
			$goods=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['goodsid']));
			if(!$item['feetype'] && $item['agio']!=0){
				$item['group_price']=price($goods['price']*$item['agio']/100);
			}elseif($item['feetype'] && $item['price']!=0){
				$item['group_price']=$item['price'];
			}else{
				$item['group_price']=price($goods['price']);
			}
			$item['goods']=$goods;
			$item['ordernum'] = pdo_count('jy_aligroup_groups_order',array('status' => array(1,2,3,4), 'groupid' => $item['id'], 'uniacid' => $_SESSION['uniacid']));
			$item['goodsnum']=$item['goodsnum']?:100;
			$item['lastnum']=$item['goodsnum']-$item['ordernum'];
		}
	}
	$return['list']=$groups;
	$return['groups_count']=$groups_count;
	exi($return);
}